import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  static const platform = MethodChannel('flutter_method_channel');

  String _smsMessage = 'No messages received yet.';
  int _count = 0;

  @override
  void initState() {
    super.initState();
    platform.setMethodCallHandler(_handleMethodChannel);
  }

  Future<void> _handleMethodChannel(MethodCall call) async {
    if (call.method == 'onSmsReceived') {
      setState(() {
        _smsMessage = call.arguments;
      });
    }

    if (call.method == 'onTick') {
      setState(() {
        _count = _count + 1;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('SMS Listener'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(_smsMessage),
              Text("timer count : $_count"),
            ],
          ),
        ),
      ),
    );
  }
}
